/*
 *  utf8.c
 *
 *  utf8
 *
 *  Copyright (C) 2008  Huang Guan
 *
 *  2008-7-10 13:31:57 Created.
 *
 *  Description: This file mainly includes the functions about 
 *  utf8
 *
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include "qqdef.hpp"
#include "debug.hpp"

#include "config.hpp"
#include "utf8.hpp"

#include <QTextCodec>


void utf8_to_gb( char* src, char* dst, int len )
{
	
	QString s=QString::fromUtf8(src);
	QTextCodec *codecGBK = QTextCodec::codecForName("GB18030");
	QByteArray ret=codecGBK->fromUnicode(s);
	memcpy(dst,ret.data(),std::min(len,ret.size()));
	dst[len]='\0';
}
void gb_to_utf8( char* src, char* dst, int len )
{
	QTextCodec *codec = QTextCodec::codecForName("GB18030");
	QString s=codec->toUnicode(QByteArray(src));
	QByteArray ret=s.toUtf8();
	memcpy(dst,ret.data(),std::min(len,ret.size()));
	dst[len]='\0';
}



